Public Class FrmDocComments
    Public EditCommet As Boolean
    Public CommentID As Integer
    Public DocumentID As Integer
    Sub Initialize_Error_Provider()
        Try
            With Me
                .ErrorProviderExtended1.Controls.Add(.txtTitle, "Comment Title")
                .ErrorProviderExtended1.Controls.Add(.txtComment, "Comment Detail")
                .ErrorProviderExtended1.SetErrorEvents()
            End With
        Catch ex As Exception
            'Logging.WriteError(ex)
        End Try
    End Sub
    Private Sub FrmDocComments_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If EditCommet = True Then
            Me.TbL_DOC_COMMENTTableAdapter1.FillByCOMMENT_ID(Me.DsTempList.TBL_DOC_COMMENT, CommentID)
            Me.btnDelete.Visible = True
        Else
            Me.btnDelete.Visible = False
            Me.TbL_DOC_COMMENTTableAdapter1.FillByCOMMENTDOC_ID(Me.DsTempList.TBL_DOC_COMMENT, DocumentID)
            Me.TBLDOCCOMMENTBindingSource.AddNew()
            txt_documentid.Text = DocumentID
            txt_comment_Date.Text = FormatDateTime(Now, DateFormat.ShortDate)
        End If
        Initialize_Error_Provider()
    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub


    Private Sub TBLDOCCOMMENTBindingSource_AddingNew(ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles TBLDOCCOMMENTBindingSource.AddingNew
        txt_documentid.Text = DocumentID
        txt_comment_Date.Text = FormatDateTime(Now, DateFormat.ShortDate)
        Me.TbL_DOC_COMMENTTableAdapter1.Update(Me.DsTempList.TBL_DOC_COMMENT)
    End Sub

    Private Sub TBLDOCCOMMENTBindingSource_BindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.BindingCompleteEventArgs) Handles TBLDOCCOMMENTBindingSource.BindingComplete
        txt_documentid.Text = DocumentID
        txt_comment_Date.Text = FormatDateTime(Now, DateFormat.ShortDate)
    End Sub

    Private Sub TBLDOCCOMMENTBindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBLDOCCOMMENTBindingSource.CurrentChanged

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If Me.txtComment.Text.Trim = "" Then
            MessageBox.Show("Invalid Comment Detail", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
        If Me.txtTitle.Text.Trim = "" Then
            MessageBox.Show("Invalid Comment Title", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End If
        If Me.EditCommet = True Then
            Me.TbL_DOC_COMMENTTableAdapter1.Update(Me.DsTempList.TBL_DOC_COMMENT)
            Me.DsTempList.TBL_DOC_COMMENT.Merge(Me.DsTempList.TBL_DOC_COMMENT)
            MessageBox.Show("Comment Sucessfully Updated", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()

        Else
            Me.TbL_DOC_COMMENTTableAdapter1.Insert(Me.txt_documentid.Text, Me.txtTitle.Text, Me.txtComment.Text, Me.txt_comment_Date.Text)
            Me.DsTempList.TBL_DOC_COMMENT.Merge(Me.DsTempList.TBL_DOC_COMMENT)
            MessageBox.Show("Comment Sucessfully Inserted", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        End If
    End Sub


    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If MessageBox.Show("Are You Want Delete Selected Comment?", "Virtual Desk", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            Dim cdata As New Data
            cdata.DS_Read("DELETE TBL_DOC_COMMENT WHERE COMMENT_ID=" & Me.CommentID, "dSdELETE")
            MessageBox.Show("Comment Sucessfully Deleted", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        End If

    End Sub
End Class